const std = @import("std");

const DEFAULT_PORT = 27015;

pub fn main() !void {
    var client = std.http.Client{
        .allocator = std.heap.page_allocator,
    };
    defer client.deinit();

    // var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
    // defer arena.deinit();

    var headers = std.http.Headers.init(std.heap.page_allocator);
    defer headers.deinit();

    var req = try client.request(std.http.Method.GET, try std.Uri.parse("http://www.baidu.com"), headers, .{});
    defer req.deinit();

    try req.start();
    try req.wait();

    var out = std.io.getStdOut();

    while (true) {
        var buf: [256]u8 = undefined;
        var r = try req.read(&buf);
        if(r == 0) break;
        try out.writeAll(buf[0..r]);
    }
}

test "simple test" {
    // var list = std.ArrayList(i32).init(std.testing.allocator);
    // defer list.deinit(); // try commenting this out and see if zig detects the memory leak!
    // try list.append(42);
    // try std.testing.expectEqual(@as(i32, 42), list.pop());
}
